package com.vertx.starter;

import com.google.inject.Inject;
import com.vertx.starter.service.UserService;
import io.vertx.core.Vertx;
import io.vertx.ext.web.Router;
import lombok.extern.log4j.Log4j2;

@Log4j2
public class UserRouterImpl implements UserRouter {

    @Inject
    private UserService userService;

    @Override
    public Router create(Vertx vertx) {
        Router router = Router.router(vertx);
        router.get("/list").handler(ctx -> {
            log.info("处理list请求：{}", ctx.request().absoluteURI());
            ctx.response().setChunked(true); // 可接收多段返回
            ctx.next(); // 可执行多个handler
        }).handler(userService::list);
        router.get("/info/:userId").handler(userService::get);
        router.post("/info").handler(userService::add);
        router.put("/info").handler(userService::update);
        router.delete("/info/:userId").handler(userService::delete);
        return router;
    }

}
